package com.tjsinfo.tjsoa.system.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.json.JSONArray;
import org.json.JSONObject;

import com.tjsinfo.tjsoa.system.bo.ISystemDutyBo;
import com.tjsinfo.tjsoa.system.vo.TSystemDuty;

/**
 * 职位查询
 * @author wangxiaowei
 *
 */
public class DutyListAction extends Action{
	private ISystemDutyBo systemDutyBo;

	public ISystemDutyBo getSystemDutyBo() {
		return systemDutyBo;
	}

	public void setSystemDutyBo(ISystemDutyBo systemDutyBo) {
		this.systemDutyBo = systemDutyBo;
	}

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// TODO Auto-generated method stub
		
		List<TSystemDuty> list;
		Integer first;
		JSONArray array = new JSONArray();
		JSONObject object = new JSONObject();
		if (request.getParameter("start") == null) {
			first = 0;
			list = systemDutyBo.selectDutyPage(0, 15);
		} else {
			first = Integer.parseInt(request.getParameter("start"));
			list = systemDutyBo.selectDutyPage(first, 15);
		}
		Integer totalProperty = systemDutyBo.selectDutyTotalLine();
		object.put("totalProperty", totalProperty);
		for (TSystemDuty systemDuty : list) {
			if (systemDuty.getIsDel() == 1) {
				systemDuty.setStart("禁用");
			} else {
				systemDuty.setStart("启用");	
			}
			systemDuty.setFirst(first);
			JSONObject systemdepartmentJSON = new JSONObject(systemDuty);
			array.put(systemdepartmentJSON);
		}
		request.getSession().setAttribute("dutyliststart", first);
		object.put("root", array);
		response.getWriter().print(object);
		return null;
	}
	
}
